*********************************************************************
9/14/17: ADDED 2018 SURVEY YEAR

9/23/17: ADDED 2017 SURVEY YEAR

8/24/17: ADDED 2016 SURVEY YEAR

11/5/10:  ADDED 2010 SURVEY YEAR

4/29/11:  ADDED VARS FOR RAILROAD SO CAN ADD IT TO SOCIAL SECURITY

7/20/11:  ADDED IPUMS_ID AND NEW VARS IN 2010 FOR SPM

8/2/11:  ADDED MORE VARS FOR WIC.  WIC MOM IS ANY MOTHER WHO HAS A KID
		 UNDER 1, SO IDENTIFY KIDS UNDER 1 BY FAMID NOT BY POVERTY FAMILY

12/20/12:  ADDED 2012 SURVEY YEAR

10/21/14:  ADDED 2014 SURVEY YEAR

10/19/15:  ADDED 2015 SURVEY YEAR

8/22/17:  ADDED 2016 SURVEY YEAR

**********************************************************************;

   filename mar92 'C:\Users\jsulliv4\Documents\CPSdata\1992_Data\1992-Data.txt';
   filename mar93 'C:\Users\jsulliv4\Documents\CPSdata\1993_Data\1993-Data.txt';
   filename mar94 'C:\Users\jsulliv4\Documents\CPSdata\1994_Data\da1994';
   filename mar95 'C:\Users\jsulliv4\Documents\CPSdata\1995_Data\da1995';
   filename mar96 'C:\Users\jsulliv4\Documents\CPSdata\1996_Data\da1996';
   filename mar97 'C:\Users\jsulliv4\Documents\CPSdata\1997_Data\1997-Data.txt';
   filename mar98 'C:\Users\jsulliv4\Documents\CPSdata\1998_Data\da1998';
   filename mar99 'C:\Users\jsulliv4\Documents\CPSdata\1999_Data\da1999';
   filename mar00 'C:\Users\jsulliv4\Documents\CPSdata\2000_Data\da2000';
*   filename mar01 'C:\Users\jsulliv4\Documents\CPSdata\2001_Data_Original\da2001';
   filename mar01 'C:\Users\jsulliv4\Documents\CPSdata\2001_Data_Expanded\chip2001pub.cps';
   filename mar02 'C:\Users\jsulliv4\Documents\CPSdata\2002_Data\2002-Data.txt';
   filename mar03 'C:\Users\jsulliv4\Documents\CPSdata\2003_Data\2003-Data.txt';

   filename mar05 'C:\Users\jsulliv4\Documents\CPSdata\2005_data\asec2005_pubuse.dat';
   filename mar06 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2006_pubuse.pub';
   filename mar07 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2007_pubuse_tax2.dat';
   filename mar08 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2008_pubuse.dat';
   filename mar09 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2009_pubuse.dat';
   filename mar10 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2010_pubuse.dat';
   filename mar11 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2011_pubuse.dat';
   filename mar12 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2012_pubuse.dat';
   filename mar13 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2013_pubuse.dat';
   filename mar14 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2014_pubuse_tax_fix_5x8_2017.dat';
   filename mar15 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2015_pubuse.dat';  
   filename mar16 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2016_pubuse_v3.dat';
   filename mar17 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2017_pubuse.dat'; 
   filename mar18 'C:\Users\worri\Dropbox\Poverty\cpsdata\asec2018_pubuse.dat'; 

   %macro read(yr,dir);

           options obs=max mprint;

           data cpsdata.all&yr;
               infile &dir missover lrecl=1000;

  
   *********************************************************************
   Reading in data from 1989,1990,1991,1992 and 1993 March CPS.
   **********************************************************************;

  IF 1988<&yr<=1993 then do;
                  hhid=_n_;
                   input rectype  1 @;
                   if rectype=1 then input
			   hseq      2-6
			   hlivqrt   31-32
			   htenure   35
			   htele     36
			   hreg 	 39
			   hmsasz    55
			   hpublic   74
			   hlorent   75
			   hengval   86-89

                     state2      40-41
			   hfdval    81-84
			   htotval   248-255
			   housret   337-341

                   @;
                  retain state2 hfdval
			hseq hlivqrt htenure htele hreg  hmsasz hpublic hlorent    
			hengval htotval housret;
                   if rectype=2 then input
                  famid 2-8
                   fkind 9
                   ftype 10
                  fpersons 11-12
                  fownu18 27
                  frelu18 29
                  fpovcut 32-36
                  famlis  37
				  fpawval  103-108
                  ftotval  205-212
                  fmvfs 243-246
				  ftotearn  213-220 
				  fsupwgt 233-240

                  fhoussub 261-263    
                  fmvrsl 247-250    
                  fngmcare 251-255    
                  fngmcaid 256-260   

					ffrval  64-70
					fseval  56-62
					fsurval  118-124
					foival  198-204 

					povll        38-39 
                    famlis       37 

                  @;

               	retain  famid fpersons fkind ftype fownu18 frelu18 
			fpovcut famlis ftotval  fmvfs
			fhoussub fmvrsl fngmcare fngmcaid ftotearn fpawval fsupwgt
			ffrval fseval fsurval foival;

                  if rectype=3 then input
                      pseq       2-6
                      ppos   	   7-8
                      pcapgain   689-693
                      pcaploss   694-697

                      hrslw   76-77

					  lfsr 145

                      pemlr   74
                      refrel2         13-14
                      age         15-16
                      marstat         17
                      sex         20
                      hga             22-23
                      hgc         24
                      race2           25
					  reorgn		  27-28
					  pertype         26
                      famrel          32
					  famrel2          35-36
                      msupwgt         66-73
                      rsnnotw         170
                      wkswrk          171-172
                      rsnnotl         179
                      hrswk           181-182
                      mainjob         228-233
                      source          234
                  wagesal1        237-241
                  selfemp1        250-254
                  ssi         297-300

					   ssinc           291-295
					   intinc          386-390
					   divinc          393-397
					   uiinc           278-282
					   wcinc		   285-289
					   pawval		   305-309
					   vetinc		   317-321
					   survinc		   337-342
	
					   retinc          379-384
					   alimony		   421-425	
					   ptotearn        448-455
					   ptotinc         440-447

			           fedtax 660-664
                       statetax 669-673
                       fica 674-678
                      eitc 665-668
                       ptotval 440-447
                       earnval 448-455
					   emcontrb 653-656

					   sur_sc1	323-324
					   sur_sc2	325-326
					   sur_val1	327-331
					   sur_val2	332-336

					   mcaid	470

                  ;

  end;
  
  *********************************************************************
  Reading in data from 1994 and 1995 March CPS.
  **********************************************************************;

  IF 1994<=&yr<=1995 then do;
                  hhid=_n_;
                  input rectype  1 @;
                  if rectype=1 then input
                      state2      40-41
					  hfdval    81-84
			   hseq      2-6
			   hlivqrt   31-32
			   htenure   35
			   htele     36
			   hreg 	 39
			   hmsasz    55
			   hpublic   74
			   hlorent   75
			   hengval   86-89
			   htotval   248-255
			   housret   337-341

                  @;
                  retain state2 hfdval
			hseq hlivqrt htenure htele hreg  hmsasz hpublic hlorent   
			hengval htotval housret;
                  if rectype=2 then input
                  famid 2-8
                  fkind 9
                  ftype 10
                  fpersons 11-12
                  fownu18 27
                  frelu18 29
                  fpovcut 32-36
                  famlis  37
				  fpawval  103-108
                 ftotval  205-212
                  fmvfs 243-246
				  ftotearn  213-220
				  fsupwgt 233-240

                  fhoussub 261-263    
                  fmvrsl 247-250    
                  fngmcare 251-255    
                  fngmcaid 256-260   

					ffrval  64-70
					fseval  56-62
					fsurval  118-124
					foival  198-204 

					povll        38-39 
                    famlis       37 

                  @;

               	retain  famid fpersons fkind ftype fownu18 frelu18 
			fpovcut ftotval fmvfs famlis  
			fhoussub fmvrsl fngmcare fngmcaid ftotearn fpawval fsupwgt
			ffrval fseval fsurval foival;

                  if rectype=3 then input
                      pseq       2-6
                      ppos   	   7-8
                      pcapgain   689-693
                      pcaploss   694-697

                      refrel2         13-14
                      age         15-16
                      marstat         17
                      sex         20
                      hga         22-23
                      race2           25
					  reorgn		  27-28
					  pertype         26
                      famrel          32
					  famrel2          35-36
                      msupwgt         66-73
                      rsnnotw         170
                      wkswrk          171-172
                      rsnnotl         179
                      hrswk           181-182
                      mainjob         228-233
                      source          234
                  wagesal1        237-241
                  selfemp1        250-254
                  ssi         297-300

					   ssinc           291-295
					   intinc          386-390
					   divinc          393-397
					   uiinc           278-282
					   wcinc		   285-289
					   pawval		   305-309
					   vetinc		   317-321
					   survinc		   337-342
	
					   retinc          379-384
					   alimony		   421-425	
					   ptotearn        448-455
					   ptotinc         440-447

                  pemlr           705
                  hrslw           76-77

				  lfsr 145
				  citizen 733

				       fedtax 660-664
                       statetax 669-673
                       fica 674-678
                       eitc 665-668
                       ptotval 440-447
                       earnval 448-455
					   emcontrb 653-656

					   sur_sc1	323-324
					   sur_sc2	325-326
					   sur_val1	327-331
					   sur_val2	332-336

					   mcaid	470

  ;
  end;
			   
  *********************************************************************
  Reading in data from 1996-2002 March CPS.  Race changes in 2003.
  Do 2004 separately b/c need to add noncash and tax vars.  
  Tax Variables change in 2005

  NOTE: WICYN FIRST AVAILABLE IN SY 2001
  **********************************************************************;

  IF 1996<=&yr<=2002 then do;
                  hhid=_n_;
                  input rectype  1 @;
                  if rectype=1 then input
                     state2      40-41
			   hfdval    81-84
			   hseq      2-6
			   hlivqrt   31-32
			   htenure   35
			   htele     36
			   hreg 	 39
			   hmsasz    55
			   hpublic   74
			   hlorent   75
 			   hengval   86-89
			   htotval   248-255
			   housret   337-341

                 @;
                  retain state2 hfdval
			hseq hlivqrt htenure htele hreg  hmsasz hpublic hlorent   
			hengval htotval housret;
                  if rectype=2 then input
                  famid 2-8
                  fkind 9
                  ftype 10
                  fpersons 11-12
                  fownu18 27
                  frelu18 29
                  fpovcut 32-36
                  famlis  37
				  fpawval  103-108
                  ftotval  205-212
                  fmvfs 243-246
				  ftotearn  213-220
				  fsupwgt 233-240

                  fhoussub 261-263    
                  fmvrsl 247-250    
                  fngmcare 251-255    
                  fngmcaid 256-260    

					ffrval  64-70
					fseval  56-62
					fsurval  118-124
					foival  198-204

					povll        38-39 
                    famlis       37 

                @;
               	retain  famid fpersons fkind ftype fownu18 frelu18 
			fpovcut ftotval fmvfs famlis
			fhoussub fmvrsl fngmcare fngmcaid ftotearn fpawval fsupwgt
			ffrval fseval fsurval foival;

                  if rectype=3 then input
                      pseq       2-6
                      ppos   	   7-8
                      pcapgain   689-693
                      pcaploss   694-697

                      refrel2         13-14
                      age         15-16
                      marstat         17
                      sex         20
                      hga         22-23
                       race2           25
					  reorgn		  27-28
					  pertype         26
                      famrel          32
					  famrel2          35-36
                      msupwgt         66-73
                      rsnnotw         170
                      wkswrk          171-172
                      rsnnotl         179
                      hrswk           181-182
                      mainjob         228-233
                      source          234
                      wagesal1        824-829
                      selfemp1        830-835
                      ssi         819-823

					   ssinc           291-295
					   intinc          386-390
					   divinc          393-397
					   uiinc           278-282
					   wcinc		   285-289
					   pawval		   305-309
					   vetinc		   317-321
					   survinc		   337-342
	
					   retinc          379-384
					   alimony		   421-425	
					   ptotearn        448-455
					   ptotinc         440-447

                     pemlr           705
                      hrslw           76-77

					  lfsr 145
					  citizen 733

                       fedtax 660-664
                       statetax 669-673
                       fica 674-678
                      eitc 665-668
                       ptotval 440-447
                       earnval 448-455
					   emcontrb 653-656

					   sur_sc1	323-324
					   sur_sc2	325-326
					   sur_val1	327-331
					   sur_val2	332-336

					   wicyn 	900
					   mcaid	470
					   paidccyn	863

                  ;

  end;

  *********************************************************************
  Reading in data from 2003 March CPS.  Race changes in 2003
  **********************************************************************;

  IF 2003<=&yr<=2003 then do;
                  hhid=_n_;
                  input rectype  1 @;
                  if rectype=1 then input
                     state2      40-41
			   hfdval    81-84
			   hseq      2-6
			   hlivqrt   31-32
			   htenure   35
			   htele     36
			   hreg 	 39
			   hmsasz    55
			   hpublic   74
			   hlorent   75
 			   hengval   86-89
			   htotval   248-255
			   housret   337-341

                 @;
                  retain state2 hfdval
			hseq hlivqrt htenure htele hreg  hmsasz hpublic hlorent   
			hengval htotval housret;
                  if rectype=2 then input
                  famid 2-8
                  fkind 9
                  ftype 10
                  fpersons 11-12
                  fownu18 27
                  frelu18 29
                  fpovcut 32-36
                  famlis  37
				  fpawval  103-108
                  ftotval  205-212
                  fmvfs 243-246
				  ftotearn  213-220
				  fsupwgt 233-240

                  fhoussub 261-263    
                  fmvrsl 247-250    
                  fngmcare 251-255    
                  fngmcaid 256-260    

					ffrval  64-70
					fseval  56-62
					fsurval  118-124
					foival  198-204

					povll        38-39 
                    famlis       37 

                @;
               	retain  famid fpersons fkind ftype fownu18 frelu18 
			fpovcut ftotval fmvfs famlis
			fhoussub fmvrsl fngmcare fngmcaid ftotearn fpawval fsupwgt
			ffrval fseval fsurval foival;

                  if rectype=3 then input
                      pseq       2-6
                      ppos   	   7-8
                      pcapgain   689-693
                      pcaploss   694-697

                      refrel2         13-14
                      age         15-16
                      marstat         17
                      sex         20
                      hga         22-23
                      race2           24-25
					  reorgn		  28
					  pertype         26
                      famrel          32
					  famrel2          35-36
                      msupwgt         66-73
                      rsnnotw         170
                      wkswrk          171-172
                      rsnnotl         179
                      hrswk           181-182
                      mainjob         228-233
                      source          234
                      wagesal1        824-829
                      selfemp1        830-835
                      ssi         819-823
                     pemlr           705

					   ssinc           291-295
					   intinc          386-390
					   divinc          393-397
					   uiinc           278-282
					   wcinc		   285-289
					   pawval		   305-309
					   vetinc		   317-321
					   survinc		   337-342
					   retinc          379-384
					   alimony		   421-425	
					   ptotearn        448-455
					   ptotinc         440-447

                      hrslw           76-77

					  lfsr 145
					  citizen 733

                       fedtax 660-664
                       statetax 669-673
                       fica 674-678
                      eitc 665-668
                       ptotval 440-447
                       earnval 448-455
					   emcontrb 653-656

					   sur_sc1	323-324
					   sur_sc2	325-326
					   sur_val1	327-331
					   sur_val2	332-336

					   wicyn 	900
					   mcaid	470
					   paidccyn	863

                  ;

  end;


*********************************************************************
  Reading in data from 2005- March CPS.
**********************************************************************;

  IF 2005<=&yr<=2008 then do;
                  hhid=_n_;
                  input rectype  1 @;
                  if rectype=1 then input
                     state2      40-41
			   hfdval    81-84
			   hseq      2-6
			   hlivqrt   31-32
			   htenure   35
			   htele     36
			   hreg 	 39
			   hmsasz    55
			   hpublic   74
			   hlorent   75
 			   hengval   86-89
			   htotval   248-255
			   housret   337-341

                 @;
                  retain state2 hfdval
			hseq hlivqrt htenure htele hreg  hmsasz hpublic hlorent   
			hengval htotval housret;
                  if rectype=2 then input
                  famid 2-8
                  fkind 9
                  ftype 10
                  fpersons 11-12
                  fownu18 27
                  frelu18 29
                  fpovcut 32-36
                  famlis  37
				  fpawval  103-108
                  ftotval  205-212
                  fmvfs 243-246
				  ftotearn  213-220
				  fsupwgt 233-240

                  fhoussub 261-263    
                  fmvrsl 247-250    
                  fngmcare 251-255    
                  fngmcaid 256-260

					ffrval  64-70
					fseval  56-62
					fsurval  118-124
					foival  198-204 

					povll        38-39 
                    famlis       37 

                @;
               	retain  famid fpersons fkind ftype fownu18 frelu18 
			fpovcut ftotval fmvfs famlis
			fhoussub fmvrsl fngmcare fngmcaid ftotearn fpawval fsupwgt
			ffrval fseval fsurval foival;

                  if rectype=3 then input
                      pseq       2-6
                      ppos   	   7-8
                      pcapgain   689-693
                      pcaploss   694-697

                      refrel2         13-14
                      age         15-16
                      marstat         17
                      sex         20
                      hga         22-23
                      race2           24-25
					  reorgn		  28
                     pertype         26
                      famrel          32
					  famrel2          35-36
                      msupwgt         66-73
                      rsnnotw         170
                      wkswrk          171-172
                      rsnnotl         179
                      hrswk           181-182
                      mainjob         228-233
                      source          234
                      wagesal1        824-829
                      selfemp1        830-835
                      ssi         819-823
                     pemlr           705
                      hrslw           76-77

					  lfsr 145
					  citizen 733

					   ssinc           291-295
					   intinc          386-390
					   divinc          393-397
					   uiinc           278-282
					   wcinc		   285-289
					   pawval		   305-309
					   vetinc		   317-321
					   survinc		   337-342
					   retinc          379-384
					   alimony		   421-425	
					   ptotearn        448-455
					   ptotinc         440-447

					 fedtax      934-938
					 fedtax_ac   939-943
					 statetax    944-948
					 statetax_ac 949-953

                       fica 674-678
                      eitc 665-668
                       ptotval 440-447
                       earnval 448-455
					   emcontrb 653-656

					   sur_sc1	323-324
					   sur_sc2	325-326
					   sur_val1	327-331
					   sur_val2	332-336

					   wicyn 	900
					   mcaid	470
					   paidccyn	863

                  ;
  end;

*********************************************************************
  Reading in data from 2009- March CPS.
  (hfdval moved)
**********************************************************************;

  IF 2009<=&yr<=2010 then do;
                  hhid=_n_;
                  input rectype  1 @;
                  if rectype=1 then input
                     state2      40-41
			   hfdval    387-391
			   hseq      2-6
			   hlivqrt   31-32
			   htenure   35
			   htele     36
			   hreg 	 39
			   hmsasz    55
			   hpublic   74
			   hlorent   75
 			   hengval   86-89
			   htotval   248-255
			   housret   337-341

                 @;
                  retain state2 hfdval
			hseq hlivqrt htenure htele hreg  hmsasz hpublic hlorent   
			hengval htotval housret;
                  if rectype=2 then input
                  famid 2-8
                  fkind 9
                  ftype 10
                  fpersons 11-12
                  fownu18 27
                  frelu18 29
                  fpovcut 32-36
                  famlis  37
				  fpawval  103-108
                  ftotval  205-212
                  fmvfs 243-246
				  ftotearn  213-220
				  fsupwgt 233-240

                  fhoussub 261-263    
                  fmvrsl 247-250    
                  fngmcare 251-255    
                  fngmcaid 256-260

					ffrval  64-70
					fseval  56-62
					fsurval  118-124
					foival  198-204

					povll        38-39 
                    famlis       37 


 
                @;
               	retain  famid fpersons fkind ftype fownu18 frelu18 
			fpovcut ftotval fmvfs famlis
			fhoussub fmvrsl fngmcare fngmcaid ftotearn fpawval fsupwgt
			ffrval fseval fsurval foival;

                  if rectype=3 then input
                      pseq       2-6
                      ppos   	   7-8
                      pcapgain   689-693
                      pcaploss   694-697

                      refrel2         13-14
                      age         15-16
                      marstat         17
                      sex         20
                      hga         22-23
                      race2           24-25
					  reorgn		  28
                     pertype         26
                      famrel          32
					  famrel2          35-36
                      msupwgt         66-73
                      rsnnotw         170
                      wkswrk          171-172
                      rsnnotl         179
                      hrswk           181-182
                      mainjob         228-233
                      source          234
                      wagesal1        824-829
                      selfemp1        830-835
                      ssi         819-823
                     pemlr           705
                      hrslw           76-77

					  lfsr 145
					  citizen 733

					   ssinc           291-295
					   intinc          386-390
					   divinc          393-397
					   uiinc           278-282
					   wcinc		   285-289
					   pawval		   305-309
					   vetinc		   317-321
					   survinc		   337-342
					   retinc          379-384
					   alimony		   421-425	
					   ptotearn        448-455
					   ptotinc         440-447

					 fedtax      934-938
					 fedtax_ac   939-943
					 statetax    944-948
					 statetax_ac 949-953

                       fica 674-678
                      eitc 665-668
                       ptotval 440-447
                       earnval 448-455
					   emcontrb 653-656

					   sur_sc1	323-324
					   sur_sc2	325-326
					   sur_val1	327-331
					   sur_val2	332-336

					   wicyn 	900
					   mcaid	470
					   paidccyn	863


                  ;
end;
**********************************************************************
  Reading in data from 2011-2014 March CPS. (SPM variables incorporated).  
  Many person level variables changed column locations
**********************************************************************;

  IF 2011<=&yr<=2014 then do;
                  hhid=_n_;
                  input rectype  1 @;
                  if rectype=1 then input
                       state2       40-41
			           hfdval       387-391
			           hseq         2-6
			           hlivqrt      31-32
			           htenure      35
			           htele        36
			           hreg 	    39
			           hmsasz       55
			           hpublic      74
			           hlorent      75
 			           hengval      86-89
			           htotval      248-255
			           housret      337-341

				/* SPM ADDED VARIABLES: */

          	           care_val     393-398 
                       tcareval     392 
                       hpres_mort   400 

                 @;
                  retain state2 hfdval
			hseq hlivqrt htenure htele hreg  hmsasz hpublic hlorent   
			hengval htotval housret care_val tcareval hpres_mort;

                  if rectype=2 then input
                       famid        2-8
                       fkind        9
                       ftype        10
                       fpersons     11-12
                       fownu18      27
                       frelu18      29
                       fpovcut      32-36
                       famlis       37
				       fpawval      103-108
                       ftotval      205-212	
                       fmvfs        243-246
				       ftotearn     213-220
				       fsupwgt      233-240

                       fhoussub     261-263    
                       fmvrsl       247-250    
                       fngmcare     251-255    
                       fngmcaid     256-260

				  	   ffrval       64-70
   				  	   fseval       56-62
					   fsurval      118-124
					   foival       198-204

					   povll        38-39 
                       famlis       37 

				/* SPM ADDED VARIABLES: */

	                   fhip_val     272-278 
                       fmoop        279-285
                       fotc_val     286-291
                       fmed_val     292-298
 
                @;
               	retain  famid fpersons fkind ftype fownu18 frelu18 
			fpovcut ftotval fmvfs famlis
			fhoussub fmvrsl fngmcare fngmcaid ftotearn fpawval fsupwgt
			ffrval fseval fsurval foival
			fhip_val fmoop fotc_val fmed_val povll famlis;

                  if rectype=3 then input
                      pseq        2-6
                      ppos   	  7-8

	                  refrel2     15-16     
                      age         19-20     
                      marstat     21        
                      sex         24        
                      hga         25-26     
                      race2       27-28     
					  reorgn	  32        
                      pertype     29        
                      famrel      36        
					  famrel2     39-40     
                      msupwgt     155-162   
                      rsnnotw     257       
                      wkswrk      258-259   
                      rsnnotl     266       
                      hrswk       268-269   
                      mainjob     355-361   
                      source      353       
                      wagesal1    371-377   
                      selfemp1    387-392   
                      ssi         433-437   
                      pemlr       218       
                      hrslw       163-164   
					  lfsr        200       
					  citizen     95        

					  ssinc       424-428   
					  intinc      526-530   
					  divinc      533-538   
					  uiinc       411-415   
					  wcinc		  418-422   
					  pawval	  445-449   
					  vetinc	  457-461   
					  survinc	  477-482   
					  retinc      519-524   
					  alimony	  561-565   
					  ptotearn    588-595   
					  ptotinc     580-587   
		/*  COL. LOCATIONS IN CODE BOOK MESSED UP IN 2011 FOR TAX VARIABLES, FIXED THEM FOR 2012, STILL 
			NEED TO GO BACK TO SEE IF THESE NEW LOCATIONS WORK FOR 2011  */
					  fedtax      772-777   
					  fedtax_ac   778-783   
					  statetax    784-789   
					  statetax_ac 790-795   

                      eitc        736-739   
                      eitc_old    740-743
					  fica        744-748
					  fica_old    748-752
                      ptotval     580-587   
                      earnval     588-595   
					  emcontrb    646-649   

					  sur_sc1	  463-464   
					  sur_sc2	  465-466   
					  sur_val1	  467-471   
					  sur_val2	  472-476   

					  wicyn 	  608       
					  mcaid	      635       
					  paidccyn    800       

					  pov_univ    607       

				/* SPM ADDED VARIABLES: */

				      moop        802-808
                      phip_val    809-814
                      potc_val    815-819
                      pmed_val    820-825
                      chsp_val    826-830
                      chsp_yn     831
                      chelsew_yn  832 
                      tphip_val   1070 
                      tpotc_val   1071 
                      tpmed_val   1072 
                      tchsp_val   1073 

		/* SPM Resource Unit ADDED VARIABLES */
               	pecohab     50-51
	       		perrp          17-18
	       		pelndad      54-55
	       		pelnmom    52-53
	       		parent        43
	       		lineno        11-12

		/* Health Insurance ADDED VARIABLES: */
			  mcare       629
			  champ 	  641
			  hi_yn	   642
			  cov_hi      708
			  cov_gh      707
               ;

end;



**********************************************************************
  Reading in data from 2015- March CPS. Some change in column locations
  i.e. food stmaps, fedtax_bc, etc. 
  
**********************************************************************;

  IF 2015<=&yr<=2018 then do;
                  hhid=_n_;
                  input rectype  1 @;
                  if rectype=1 then input

				/* GOT RID OF GESTCEN (CENSUS STATE CODE
				   state2       40-41)
				   SO WILL HAVE TO USE FIPSSTATE */
					   state3       42-43
			           hfdval       387-391
			           hseq         2-6
			           hlivqrt      31-32
			           htenure      35
			           htele        36
			           hreg 	    39
			           hmsasz       55
			           hpublic      74
			           hlorent      75
 			           hengval      86-89
			           htotval      248-255
			           housret      337-341

				/* SPM ADDED VARIABLES: */

          	           care_val     393-398 
                       tcareval     392 
                       hpres_mort   400 

                 @;
                  retain state3 hfdval
			hseq hlivqrt htenure htele hreg  hmsasz hpublic hlorent   
			hengval htotval housret care_val tcareval hpres_mort;

                  if rectype=2 then input
                       famid        2-8
                       fkind        9
                       ftype        10
                       fpersons     11-12
                       fownu18      27
                       frelu18      29
                       fpovcut      32-36
                       famlis       37
				       fpawval      103-108
                       ftotval      205-212	
                       fmvfs        243-247
				       ftotearn     213-220
				       fsupwgt      233-240

                       fhoussub     261-263    
                       fmvrsl       248-251    

				/* THESE MEDICAID AND MEDICARE VARIABLES HAVE BEEN CUT 
					   fngmcare     251-255    
                       fngmcaid     256-260  */

				  	   ffrval       64-70
   				  	   fseval       56-62
					   fsurval      118-124
					   foival       198-204

					   povll        38-39 
                       famlis       37 

				/* SPM ADDED VARIABLES: */

	                   fhip_val     272-278 
                       fmoop        279-285
                       fotc_val     286-291
                       fmed_val     292-298
 
                @;
               	retain  famid fpersons fkind ftype fownu18 frelu18 
			fpovcut ftotval fmvfs famlis
			fhoussub fmvrsl ftotearn fpawval fsupwgt
			ffrval fseval fsurval foival
			fhip_val fmoop fotc_val fmed_val povll famlis;

                  if rectype=3 then input
                      pseq        2-6
                      ppos   	  7-8

	                  refrel2     15-16     
                      age         19-20     
                      marstat     21        
                      sex         24        
                      hga         25-26     
                      race2       27-28     
					  reorgn	  32        
                      pertype     29        
                      famrel      36        
					  famrel2     39-40     
                      msupwgt     155-162   
                      rsnnotw     257       
                      wkswrk      258-259   
                      rsnnotl     266       
                      hrswk       268-269   
                      mainjob     355-361   
                      source      353       
                      wagesal1    371-377   
                      selfemp1    387-392   
                      ssi         433-437   
                      pemlr       218       
                      hrslw       163-164   
					  lfsr        200       
					  citizen     95        

					  ssinc       424-428   
					  intinc      526-530   
					  divinc      533-538   
					  uiinc       411-415   
					  wcinc		  418-422   
					  pawval	  445-449   
					  vetinc	  457-461   
					  survinc	  477-482   
					  retinc      519-524   
			/*		  alimony	  561-565   REMOVED IN 2015 */
					  ptotearn    588-595   
					  ptotinc     580-587   
		/*  COL. LOCATIONS IN CODE BOOK MESSED UP IN 2011 FOR TAX VARIABLES, FIXED THEM FOR 2012, STILL 
			NEED TO GO BACK TO SEE IF THESE NEW LOCATIONS WORK FOR 2011  */
					  fedtax      770-776   
					  fedtax_ac   777-783   
					  statetax    784-789   
					  statetax_ac 790-795   

                      eitc        736-739   
                      eitc_old    740-743
					  fica        744-748
					  fica_old    748-752

                      ptotval     580-587   
                      earnval     588-595   
					  emcontrb    646-649   

					  sur_sc1	  463-464   
					  sur_sc2	  465-466   
					  sur_val1	  467-471   
					  sur_val2	  472-476   

					  wicyn 	  608       
					  mcaid	      635       
					  paidccyn    800       

					  pov_univ    607       

				/* SPM ADDED VARIABLES: */

				      moop        802-808
                      phip_val    809-814
                      potc_val    815-819
                      pmed_val    820-825
                      chsp_val    826-830
                      chsp_yn     831
                      chelsew_yn  832 
                      tphip_val   1070 
                      tpotc_val   1071 
                      tpmed_val   1072 
                      tchsp_val   1073 

		/* SPM Resource Unit ADDED VARIABLES */
               	pecohab     50-51
	       		perrp          17-18
	       		pelndad      54-55
	       		pelnmom    52-53
	       		parent        43
	       		lineno        11-12

		/* Health Insurance ADDED VARIABLES: */
			  mcare       629
			  champ 	  641
			  hi_yn	   642
			  cov_hi      708
			  cov_gh      707
               ;

end;



if rectype^=3 then delete;

year=&yr;
ref_year=year-1;
tottax=fedtax+statetax+fica-eitc;

IF sur_sc1=5 THEN rr1=1;
	ELSE rr1=0;
IF sur_sc2=5 THEN rr2=1;
	ELSE rr2=0;
railroad=sur_val1*rr1+sur_val2*rr2;
ssinc_rr=ssinc+railroad;

tot_trans=ssinc+uiinc+wcinc+vetinc+pawval+ssi+railroad;


IF mcaid=1 THEN mcaid_yes=1;
   ELSE mcaid_yes=0;

IF 0 LE age LE 4 THEN kid_0_4=1;
   ELSE kid_0_4=0;

IF age=0 THEN infant=1;
   ELSE infant=0;

IF famrel IN (1,2) AND sex=2 THEN pot_wic_mom=1;
   ELSE pot_wic_mom=0;

IF wicyn=1 THEN num_wic=1;
   ELSE num_wic=0;
run;

data cpsdata.all&yr;
set cpsdata.all&yr;

ipums_id=_N_;
run;


proc sort data=cpsdata.all&yr;
   by famid;
run;
proc means sum noprint data=cpsdata.all&yr;
   by famid;
   var tottax fedtax statetax fica eitc pcapgain pcaploss emcontrb tot_trans ssinc_rr mcaid_yes kid_0_4 wkswrk infant pot_wic_mom pawval num_wic chsp_val;
   output out=temp sum=ftottax ffedtax fstatetax ffica feitc fcapgain fcaploss femcontrb ftot_trans fssinc_rr 
					   fmcaid fkid_0_4 fwkswrk finfant fpot_wic_mom fpawval fnum_wic fchsp_val;
run;

data cpsdata.all&yr;
   merge cpsdata.all&yr 
         temp (keep=famid ftottax ffedtax fstatetax ffica feitc fcapgain fcaploss femcontrb ftot_trans fssinc_rr
					fmcaid fkid_0_4 fwkswrk finfant fpot_wic_mom fpawval fnum_wic fchsp_val);
   by famid; 
run;

data temp;
   set cpsdata.all&yr;
   by famid;
   if first.famid; 
run;
proc sort data=temp;
   by hseq;
run;
* exclude the related subfamilies because their values of the following are 
  already included in the values for the primary family;
proc means sum noprint data=temp;
   by hseq;
   where ftype NE 3;
   var fmvfs fhoussub fmvrsl fngmcare fngmcaid ftotearn fpersons frelu18;
   output out=temp1 sum=hmvfs hhoussub hmvrsl hngmcare hngmcaid htotearn hpersons hrelu18;
run;

proc sort data=cpsdata.all&yr;
   by hseq;
run;
proc means sum noprint data=cpsdata.all&yr;
   by hseq;
   var tottax fedtax statetax fica eitc pcapgain pcaploss emcontrb tot_trans ssinc_rr;
   output out=temp sum=htottax hfedtax hstatetax hfica heitc hcapgain hcaploss hemcontrb htot_trans hssinc_rr;
run;

data cpsdata.all&yr;
   merge cpsdata.all&yr 
         temp (keep= hseq htottax hfedtax hstatetax hfica heitc hcapgain hcaploss hemcontrb htot_trans hssinc_rr)
		 temp1 (keep=hseq hmvfs hhoussub hmvrsl hngmcare hngmcaid htotearn hpersons hrelu18);
   by hseq; 
run;

proc means data=cpsdata.all&yr;
run;

%mend read;
/*
%read(1992,mar92);
%read(1993,mar93);
%read(1994,mar94);
%read(1995,mar95);
%read(1996,mar96);
%read(1997,mar97);
%read(1998,mar98);
%read(1999,mar99);
%read(2000,mar00);
%read(2001,mar01);
%read(2002,mar02);
%read(2003,mar03);
%read(2005,mar05);
*/
%read(2006,mar06);
%read(2007,mar07);
%read(2008,mar08);
%read(2009,mar09);
%read(2010,mar10);
%read(2011,mar11);
%read(2012,mar12);
%read(2013,mar13);
%read(2014,mar14);
%read(2015,mar15);
%read(2016,mar16);
%read(2017,mar17);
%read(2018,mar18);

*NOTE do 2004 separately becasue need to merge in noncash benefits and taxes.;

proc compare base=cpsdata.all2009_bak
             compare=cpsdata.all2009
			 novalues listall;
run;
